<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title></title>
		<link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<script src="../js/jquery-3.5.1.js"></script>
		<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="login.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			html,
			body,
			.container {
				height: 100%;
				width: 100%;
			}
			#one{
				position: relative;
				top: 50%;
				left: 50%;
				transform: translate(-50%,-50%);
				 width: 550px;
				/*
				height: 100px;
				background-color: #000000; */
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div id="one">
				<form class="form-horizontal">
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">用户名:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="pit_name" placeholder="用户名">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputPassword3" class="col-sm-2 control-label">密码:</label>
				    <div class="col-sm-10">
				      <input type="password" class="form-control" id="inp_Password" placeholder="Password">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputPassword3" class="col-sm-2 control-label">重复密码:</label>
				    <div class="col-sm-10">
				      <input type="password" class="form-control" id="con_Password" placeholder="Password">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">姓名:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="ipt_xm" placeholder="姓名">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">性别:</label>
				    <div class="col-sm-10">
				      <label class="radio-inline">
				        <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="nan"> 男
				      </label>
				      <label class="radio-inline">
				        <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="nv"> 女
				      </label>
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">联系电话:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="inp_dianh" placeholder="电话号码">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">管理宿舍楼:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="inp_address" placeholder="管理宿舍楼号">
				    </div>
				  </div>
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button id="btn_save" type="button" class="btn btn-default btn-primary" onclick="save()">保存</button>
					   <button type="button" class="btn btn-default btn-primary">返回</button>
				    </div>
				  </div>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			let adminarr=localStorage.getItem("adminarr");
				let xb=null;
				$("input[type='radio']").change(function(){
					xb=$(this).val();
				})
				let edit=JSON.parse(sessionStorage.getItem("editname"));
				if (edit) {
					$("#pit_name").val(edit.name);
					$("#inp_Password").val(edit.password);
					$("#con_Password").val(edit.password);
					$("#ipt_xm").val(edit.name);
					$("#inp_dianh").val(edit.Telephone);
					$("#inp_address").val(edit.address);
					$("input[type='radio']").val(edit.Gender);
				}
			function save(){
				adminarr=JSON.parse(adminarr);
				console.log(adminarr);
				let name=$("#pit_name").val();
				let Password=$("#inp_Password").val();
				let con_Password=$("#con_Password").val();
				let xm=$("#ipt_xm").val();
				console.log(xm);
				let telephone=$("#inp_dianh").val();
				let address=$("#inp_address").val();
				if(Password!==con_Password){
					alert("密码不一致");
					return;
				}
				let tem=0;
				for(let item of adminarr){
					let id1=parseInt(item.id);
					if (tem<id1) {
						tem=id1;
					}
				}
				
				let obj={
					id:tem+1,
					name:name,
					Gender:xb,
					address:address,
					Telephone:telephone,
					password:Password
				}
				if (adminarr) {
					for (let item of adminarr) {
						if (name===item.name) {
							alert("用户名已被注册");
							return;
						}
					}
					adminarr.push(obj);
					localStorage.setItem("adminarr",JSON.stringify(adminarr));
					console.log(obj);
					location.href="yem_administrators.html"
				} else{
					alert("输入完整信息");
				}
			}
			
		</script>
	</body>
</html>
